<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 定时任务完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        pre code {
            color: #d4d4d4;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
        }
        .timeline-item {
            position: relative;
            padding-left: 40px;
        }
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 30px;
            bottom: -30px;
            width: 2px;
            background: #e5e7eb;
        }
        .timeline-item:last-child::before {
            display: none;
        }
        .timeline-dot {
            position: absolute;
            left: 0;
            top: 8px;
            width: 24px;
            height: 24px;
            background: #667eea;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 12px;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        .cron-example {
            background: #f3f4f6;
            border-left: 4px solid #667eea;
            padding: 1rem 1.5rem;
            margin: 0.5rem 0;
            border-radius: 0 8px 8px 0;
            transition: all 0.3s ease;
        }
        .cron-example:hover {
            background: #e5e7eb;
            transform: translateX(5px);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <div class="mb-6">
                    <i class="fas fa-clock text-6xl opacity-80"></i>
                </div>
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                    Spring Boot 定时任务
                </h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                    掌握 @Scheduled 注解，轻松实现自动化任务调度
                </p>
                <div class="mt-10 flex justify-center space-x-6">
                    <div class="text-center">
                        <div class="text-3xl font-bold">5分钟</div>
                        <div class="text-sm opacity-80">快速上手</div>
                    </div>
                    <div class="text-center">
                        <div class="text-3xl font-bold">4种</div>
                        <div class="text-sm opacity-80">调度方式</div>
                    </div>
                    <div class="text-center">
                        <div class="text-3xl font-bold">∞</div>
                        <div class="text-sm opacity-80">应用场景</div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">在</span>Spring Boot 中实现定时任务非常简单，主要通过使用 <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">@Scheduled</code> 注解来配置和管理任务。无论是简单的周期性任务，还是复杂的 Cron 表达式调度，Spring Boot 都能轻松应对。
                </p>
            </div>
        </section>

        <!-- Implementation Steps -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 serif-font">
                <i class="fas fa-layer-group text-purple-600 mr-3"></i>实现步骤
            </h2>
            
            <div class="timeline-item mb-12">
                <div class="timeline-dot">1</div>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-bold mb-3 text-gray-800">添加依赖</h3>
                    <p class="text-gray-600 leading-relaxed">
                        确保你的项目中包含了 Spring Boot 的基础依赖。如果你使用的是 Maven，<code class="bg-gray-100 text-gray-700 px-2 py-1 rounded text-sm">spring-boot-starter</code> 已经默认包含了所需的依赖。
                    </p>
                </div>
            </div>

            <div class="timeline-item mb-12">
                <div class="timeline-dot">2</div>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-bold mb-3 text-gray-800">启用定时任务支持</h3>
                    <p class="text-gray-600 leading-relaxed mb-4">
                        在你的 Spring Boot 应用程序主类或配置类上使用 <code class="bg-gray-100 text-gray-700 px-2 py-1 rounded text-sm">@EnableScheduling</code> 注解来启用定时任务功能。
                    </p>
                    <div class="code-block">
                        <div class="code-header">
                            <span><i class="fab fa-java mr-2"></i>DemoApplication.java</span>
                            <i class="fas fa-copy text-gray-500 cursor-pointer hover:text-white"></i>
                        </div>
                        <pre><code>import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}</code></pre>
                    </div>
                </div>
            </div>

            <div class="timeline-item mb-12">
                <div class="timeline-dot">3</div>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <h3 class="text-xl font-bold mb-3 text-gray-800">创建定时任务</h3>
                    <p class="text-gray-600 leading-relaxed mb-4">
                        使用 <code class="bg-gray-100 text-gray-700 px-2 py-1 rounded text-sm">@Scheduled</code> 注解在你的方法上定义一个定时任务。
                    </p>
                    <div class="code-block">
                        <div class="code-header">
                            <span><i class="fab fa-java mr-2"></i>ScheduledTasks.java</span>
                            <i class="fas fa-copy text-gray-500 cursor-pointer hover:text-white"></i>
                        </div>
                        <pre><code>import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTasks {

    // 每隔5秒执行一次
    @Scheduled(fixedRate = 5000)
    public void scheduleTaskWithFixedRate() {
        System.out.println("定时任务 - 固定速率执行: " + System.currentTimeMillis() / 1000);
    }

    // 每隔10秒执行一次，上次任务执行完成后等待10秒再执行
    @Scheduled(fixedDelay = 10000)
    public void scheduleTaskWithFixedDelay() {
        System.out.println("定时任务 - 固定延迟执行: " + System.currentTimeMillis() / 1000);
    }

    // 第一次延迟2秒后执行，之后每隔5秒执行一次
    @Scheduled(initialDelay = 2000, fixedRate = 5000)
    public void scheduleTaskWithInitialDelay() {
        System.out.println("定时任务 - 延迟后固定速率执行: " + System.currentTimeMillis() / 1000);
    }

    // 使用Cron表达式，每分钟的第10秒执行一次
    @Scheduled(cron = "10 * * * * *")
    public void scheduleTaskWithCronExpression() {
        System.out.println("定时任务 - 使用Cron表达式: " + System.currentTimeMillis() / 1000);
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Task Types -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 serif-font">
                <i class="fas fa-tasks text-purple-600 mr-3"></i>定时任务类型
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">fixedRate</h3>
                    <p class="text-gray-600 leading-relaxed">
                        按固定速率执行，任务之间的间隔时间是任务开始时的间隔时间。适用于需要严格按照时间间隔执行的场景。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-hourglass-half"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">fixedDelay</h3>
                    <p class="text-gray-600 leading-relaxed">
                        按固定延迟执行，任务之间的间隔时间是任务结束时的间隔时间。确保任务执行完成后才开始计时。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-stopwatch"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">initialDelay</h3>
                    <p class="text-gray-600 leading-relaxed">
                        第一次任务执行的延迟时间，通常与 <code class="bg-gray-100 text-gray-700 px-2 py-1 rounded text-sm">fixedRate</code> 或 <code class="bg-gray-100 text-gray-700 px-2 py-1 rounded text-sm">fixedDelay</code> 配合使用。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-calendar-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3 text-gray-800">cron